package hqyj.example.itemservice.controller;

import hqyj.example.itemservice.service.UsersService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

//@Controller
@RestController
@RequestMapping("users")
public class UsersController {

    @Resource
    private UsersService usersService;

    @GetMapping("auth")
    public Map<String,Object> login(String username,String password){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            if(usersService.login(username,password)){
                result.put("code",200);
                result.put("msg","登录成功！");
                return result;
            }
            result.put("code",400);
            result.put("msg","登录失败，请检查用户名或者密码是否正确！");
            return result;
        }catch(Exception ex){
            ex.printStackTrace();
            result.put("code",400);
            result.put("msg","登录出现错误！");
            return result;
        }
    }

}
